package log

import (
	"autoDeploy/service/log"
	"github.com/gin-gonic/gin"
	"github.com/golang-jwt/jwt"
)

type Log struct{}

// GetLog 根据用户id获取用户的全部推送消息
func (l Log) GetLog(c *gin.Context) {
	claims, _ := c.Get("claims")
	if claims != nil {
		claimsMap := claims.(jwt.MapClaims)
		//获取用户id
		UserIDFloat := claimsMap["user_id"].(float64)
		UserID := uint64(int64(UserIDFloat))
		//调用service层方法，获取用户的项目推送信息
		projectLogs, err := log.GetProjectLogs(UserID)
		if err != nil {
			c.JSON(200, gin.H{"code": 0, "user_id": UserID, "project_push_msg": projectLogs, "message": "根据用户id查询推送信息失败" + err.Error()})
			return
		}
		c.JSON(200, gin.H{"code": 1, "user_id": UserID, "project_push_msg": projectLogs, "message": "根据用户id查询推送信息成功"})
		return
	}
}
